import { useRouter } from 'vue-router'
import { ConfigClass } from './config'
import { ref } from 'vue'
import { ArticeApi } from '../article-manage/article-list/api'
import { NoticeApi } from '../notice-manage/api'
export class StateClass {
	configClass
	public router = useRouter()
	public activeName = ref('home')
	public articleList = ref()
	public noticeList = ref()
	constructor() {
		this.configClass = new ConfigClass()
		this.getArticleList()
		this.getNotice()
	}

	/**
	 * menu
	 */
	public getMenu() {
		return this.configClass.menu
	}

	/**
	 * 获取公告
	 */
	public getNotice() {
		const params = {
			currentPage: 1,
			pageSize: 10,
			publish: 1
		}
		NoticeApi.getTable(params).subscribe((res: any) => {
			this.noticeList.value = res.records ?? []
		})
	}
	/**
	 * 获取文章列表
	 */
	public getArticleList() {
		const params = {
			currentPage: 1,
			pageSize: 10,
			publish: 1
		}
		ArticeApi.queryArticel(params).subscribe((res: any) => {
			this.articleList.value = res.records ?? []
		})
	}
	/**
	 * 跳转后台
	 */
	public toWeb() {
		this.router.push({ name: 'Home' })
	}

	public logout() {
		localStorage.removeItem('token')
		this.router.replace('/login')
	}
}
